package com.bruce.ai.alibaba.mutil.agent.controller;

import java.util.Optional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.cloud.ai.graph.OverAllState;
import com.alibaba.cloud.ai.graph.agent.ReactAgent;
import com.alibaba.cloud.ai.graph.exception.GraphRunnerException;

@RestController
@RequestMapping("/api/agents")
public class MutilAgentController {

    @Autowired
    @Qualifier("orchestratorAgent")
    private ReactAgent orchestratorAgent ;

    @RequestMapping("/invoke")
    public String orchestrator(@RequestParam(value = "messages", defaultValue = "请写一篇关于友谊的散文，约200字，需要评审") String messages) throws GraphRunnerException{
        Optional<OverAllState>  result = orchestratorAgent.invoke(messages) ;
        if (result.isPresent()) {
            return result.get().toString();
        }
        return "找不到结果" ;
    }

}
